package com.yqy.android;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.base.base.BaseTitleActivity;
import com.android.base.dialog.fragment.SimpleDialogFragment;
import com.android.base.dialog.iface.ISimpleDialogListener;
import com.android.base.module.http.callback.ChildSubscriber;
import com.android.base.module.http.callback.OnNetRequestListener;
import com.android.base.util.JfwSignHelper;
import com.yqy.android.common.PanelFormManager;
import com.yqy.android.entity.UserInfo;
import com.yqy.android.presenter.TestPresenter;
import com.yqy.android.service.RetrofitService;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.OnClick;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class TestActivity1 extends BaseTitleActivity implements View.OnClickListener,ISimpleDialogListener{

    @Bind(R.id.activity_test1)
    RelativeLayout activityTest1;
    @Bind(R.id.tv)
    TextView tv;
    @Inject
    protected TestPresenter mTestPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SimpleDialogFragment.createBuilder(TestActivity1.this,getSupportFragmentManager())
                .setCancelable(false).setMessage("哈哈").setTitle("sasdasd").setNegativeButtonText("取消").setPositiveButtonText("确定").show();
    }
    @Override
    public int getPanelID() {
        return PanelFormManager.ID_LOGIN;
    }

    @Override
    protected void initHeaderTitle() {
        setHeaderTitle("Test1");
    }

    @OnClick(R.id.tv)
    @Override
    public void onClick(View view) {
//        PanelManager.getInstance().switchPanel(PanelFormManager.ID_TEST2,null,null);
        mTestPresenter.setString("hahahhaha");
        showLoadingDialog();
        Observable<UserInfo> observable = RetrofitService.getInstance().
                createShowApi().getTemporAccount(RetrofitService.getCacheControl(), JfwSignHelper.doBizParams(null));

        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ChildSubscriber<UserInfo>(new OnNetRequestListener() {
                    @Override
                    public void onStart() {
                        Log.d("yqy","onStart");
                    }

                    @Override
                    public void onFinish() {
                        Log.d("yqy","onFinish");
                        hideLoadingDialog();
                    }

                    @Override
                    public void onSuccess(Object data) {
                        Log.d("yqy","onSuccess " + data.toString());
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        Log.d("yqy","onFailure");
                    }
                }){});
    }

    @Override
    public int pageStyle() {
        return STYLE_1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_test1;
    }

    @Override
    public void onNegativeButtonClicked(int requestCode) {
        Log.d("yqy","" + requestCode);
    }

    @Override
    public void onNeutralButtonClicked(int requestCode) {
        Log.d("yqy","" + requestCode);
    }

    @Override
    public void onPositiveButtonClicked(int requestCode) {
        Log.d("yqy","" + requestCode);
    }
}
